Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
+#include <cstdio> // for printf, snprintf
+#include <cstdlib> // for qsort
+
+#include <QtCore/QByteArray> // for QByteArray
+#include <QtCore/QDebug> // for QDebug
+#include <QtCore/QTextCodec> // for QTextCodec
+
#include "defs.h"
-#include "cet.h"
+#include "cet.h" // for cet_cs_vec_t, cet_str_any_to_utf8, cet_str_utf8_to_any, cet_str_any_to_uni
#include "cet_util.h"
-#include "src/core/logging.h"
-#include <QtCore/QDebug>
-#include <QtCore/QTextCodec>
-#include <cstdlib> // qsort
+#include "src/core/logging.h" // for Fatal
+
#define MYNAME "cet_util"
/* %%% fixed inbuild character sets %%% */
-#include "cet/ansi_x3_4_1968.h"
-#include "cet/cp1252.h"
-#include "cet/iso_8859_8.h"
+#include "cet/ansi_x3_4_1968.h" // for cet_cs_vec_ansi_x3_4_1968, cet_cs_name_ansi_x3_4_1968
+#include "cet/cp1252.h" // for cet_cs_name_cp1252, cet_cs_vec_cp1252
+#include "cet/iso_8859_8.h" // for cet_cs_name_iso_8859_8, cet_cs_vec_iso_8859_8
/* %%% short hand strings transmission for main character sets %%% */
(const_cast<Waypoint*>(wpt))->wpt_flags.cet_converted = 1;
}
-static void
-cet_flag_route(const route_head* rte)
-{
- (const_cast<route_head*>(rte))->cet_converted = 1;
-}
-
static void
cet_flag_all()
{
waypt_disp_all(cet_flag_waypt);
- route_disp_all(cet_flag_route, nullptr, cet_flag_waypt);
- track_disp_all(cet_flag_route, nullptr, cet_flag_waypt);
+ route_disp_all(nullptr, nullptr, cet_flag_waypt);
+ track_disp_all(nullptr, nullptr, cet_flag_waypt);
}
/* -------------------------------------------------------------------- */
}
}
-/* cet_convert_route_hdr: internal used within cet_convert_strings process */
-
-static void
-cet_convert_route_hdr(const route_head* route)
-{
- auto* rte = const_cast<route_head*>(route);
-
- if ((cet_output == 0) && (rte->cet_converted != 0)) {
- return;
- }
-
- rte->cet_converted = 1;
-}
-
-/* cet_convert_route_tlr: internal used within cet_convert_strings process */
-
-static void
-cet_convert_route_tlr(const route_head* route)
-{
- (void)route;
-}
-
/* %%% cet_convert_strings (public) %%%
*
* - Convert all well known strings of GPS data from or to UTF-8 -
* !!! One of "source" or "target" must be internal cet_cs_vec_utf8 or NULL !!! */
void
-cet_convert_strings(const cet_cs_vec_t* source, const cet_cs_vec_t* target, const char* format)
+cet_convert_strings(const cet_cs_vec_t* source, const cet_cs_vec_t* target)
{
const char* cs_name_from, *cs_name_to;
- (void)format;
converter = nullptr;
}
waypt_disp_all(cet_convert_waypt);
- route_disp_all(cet_convert_route_hdr, cet_convert_route_tlr, cet_convert_waypt);
- track_disp_all(cet_convert_route_hdr, cet_convert_route_tlr, cet_convert_waypt);
+ route_disp_all(nullptr, nullptr, cet_convert_waypt);
+ track_disp_all(nullptr, nullptr, cet_convert_waypt);
cet_output = 0;
#include <QtCore/QByteArray> // for QByteArray
#include <QtCore/QList> // for QList
#include <QtCore/QString> // for QString, operator!=, operator==
+#include <QtCore/QVector> // for QVector
#include <QtCore/Qt> // for CaseInsensitive
#include <QtCore/QtGlobal> // for qPrintable, Q_UNUSED, foreach
return rv;
}
-#if GDB_DEBUG
-static char*
-nice(const char* str)
-{
- char* res, *env;
- cet_cs_vec_t* vec;
-
- if (!(str && *str)) {
- return "";
- }
-
- env = getenv("LANG");
- if (env == NULL) {
- return (char*)str;
- }
-
- if ((res = strchr(env, '.'))) {
- env = ++res;
- }
- vec = cet_find_cs_by_name(env);
-
- if ((vec != NULL) && (vec != global_opts.charset)) {
- static char buf[128];
- res = cet_str_any_to_any(str, global_opts.charset, vec);
- strncpy(buf, res, sizeof(buf));
- xfree(res);
- return buf;
- } else {
- return (char*)str;
- }
-}
-#endif
-
static char*
gdb_fread_cstr(gbfile* fin)
{
char* str;
#ifdef GMSD_EXPERIMENTAL
char subclass[22];
-#endif
-#if GDB_DEBUG
- char* sn;
#endif
waypt_ct++;
res = new Waypoint;
gmsd = garmin_fs_alloc(-1);
fs_chain_add(&res->fs, (format_specific_data*) gmsd);
res->shortname = fread_cstr();
-#if GDB_DEBUG
- sn = xstrdup(nice(res->shortname));
-#endif
wpt_class = (gt_waypt_classes_e) FREAD_i32;
GMSD_SET(wpt_class, wpt_class);
if (wpt_class != 0) {
#if GDB_DEBUG
DBG(GDB_DBG_WPTe, 1)
printf(MYNAME "-wpt \"%s\" (%d): Altitude = %.1f\n",
- sn, wpt_class, alt);
+ qPrintable(res->shortname), wpt_class, alt);
#endif
}
}
#if GDB_DEBUG
DBG(GDB_DBG_WPT, 1)
printf(MYNAME "-wpt \"%s\": coordinates = %c%0.6f %c%0.6f\n",
- sn,
+ qPrintable(res->shortname),
res->latitude < 0 ? 'S' : 'N', res->latitude,
res->longitude < 0 ? 'W' : 'E', res->longitude);
#endif
res->notes = fread_cstr();
#if GDB_DEBUG
- DBG(GDB_DBG_WPTe, res->notes) {
- char* str = gstrsub(res->notes, "\r\n", ", ");
+ DBG(GDB_DBG_WPTe, !res->notes.isNull())
printf(MYNAME "-wpt \"%s\" (%d): notes = %s\n",
- sn, wpt_class, nice(str));
- xfree(str);
- }
+ qPrintable(res->shortname), wpt_class,
+ qPrintable(QString(res->notes).replace("\r\n", ", ")));
#endif
if (FREAD_C == 1) {
WAYPT_SET(res, proximity, FREAD_DBL);
#if GDB_DEBUG
DBG(GDB_DBG_WPTe, 1)
printf(MYNAME "-wpt \"%s\" (%d): Proximity = %.1f\n",
- sn, wpt_class, res->proximity / 1000);
+ qPrintable(res->shortname), wpt_class, res->proximity / 1000);
#endif
}
i = FREAD_i32;
#if GDB_DEBUG
DBG(GDB_DBG_WPTe, i)
printf(MYNAME "-wpt \"%s\" (%d): display = %d\n",
- sn, wpt_class, i);
+ qPrintable(res->shortname), wpt_class, i);
#endif
switch (i) { /* display value */
case gt_gdb_display_mode_symbol:
#if GDB_DEBUG
DBG(GDB_DBG_WPTe, 1)
printf(MYNAME "-wpt \"%s\" (%d): Depth = %.1f\n",
- sn, wpt_class, res->depth);
+ qPrintable(res->shortname), wpt_class, res->depth);
#endif
}
FREAD(buf, 2);
}
- (void) FREAD_CSTR_AS_QSTR; /* undocumented & unused string */
#if GDB_DEBUG
- DBG(GDB_DBG_WPTe, temp)
+ QString temp = FREAD_CSTR_AS_QSTR; /* undocumented & unused string */
+ DBG(GDB_DBG_WPTe, !temp.isEmpty())
printf(MYNAME "-wpt \"%s\" (%d): Unknown string = %s\n",
- sn, wpt_class, nice(temp));
+ qPrintable(res->shortname), wpt_class, qPrintable(temp));
+#else
+ (void) FREAD_CSTR_AS_QSTR; /* undocumented & unused string */
#endif
QString linky = FREAD_CSTR_AS_QSTR;
#if GDB_DEBUG
DBG(GDB_DBG_WPTe, 1)
printf(MYNAME "-wpt \"%s\" (%d): url(%d) = %s\n",
- sn, wpt_class, url_ct - i, qPrintable(str));
+ qPrintable(res->shortname), wpt_class, url_ct - i, qPrintable(str));
#endif
}
}
}
#if GDB_DEBUG
- DBG(GDB_DBG_WPTe, res->description)
+ DBG(GDB_DBG_WPTe, !res->description.isNull())
printf(MYNAME "-wpt \"%s\" (%d): description = %s\n",
- sn, wpt_class, nice(res->description));
- DBG(GDB_DBG_WPTe, !res->url.isNull())
+ qPrintable(res->shortname), wpt_class, qPrintable(res->description));
+ DBG(GDB_DBG_WPTe, res->urls.HasUrlLink())
printf(MYNAME "-wpt \"%s\" (%d): url = %s\n",
- sn, wpt_class, nice(qPrintable(res->url))); // FIXME: qPrintable and nice probably are fighting.
+ qPrintable(res->shortname), wpt_class, qPrintable(res->urls.GetUrlLink().url_));
#endif
i = FREAD_i16;
if (i != 0) {
#if GDB_DEBUG
DBG(GDB_DBG_WPTe, i)
printf(MYNAME "-wpt \"%s\" (%d): category = %d\n",
- sn, wpt_class, i);
+ qPrintable(res->shortname), wpt_class, i);
#endif
if (FREAD_C == 1) {
#if GDB_DEBUG
DBG(GDB_DBG_WPTe, 1)
printf(MYNAME "-wpt \"%s\" (%d): temperature = %.1f\n",
- sn, wpt_class, res->temperature);
+ qPrintable(res->shortname), wpt_class, res->temperature);
#endif
}
#if GDB_DEBUG
DBG(GDB_DBG_WPTe, icon != GDB_DEF_ICON)
printf(MYNAME "-wpt \"%s\" (%d): icon = \"%s\" (MapSource symbol %d)\n",
- sn, wpt_class, nice(qPrintable(res->icon_descr)), icon); // FIXME: qPrintable and nice probably are fighting.
+ qPrintable(res->shortname), wpt_class, qPrintable(res->icon_descr), icon);
#endif
if ((str = GMSD_GET(cc, NULL))) {
if (! GMSD_HAS(country)) {
GMSD_UNSET(subclass);
#endif
}
-#if GDB_DEBUG
- xfree(sn);
-#endif
*waypt_class_out = wpt_class;
return res;
}
#if GDB_DEBUG
DBG(GDB_DBG_RTE, 1)
printf(MYNAME "-rte \"%s\": loading route with %d point(s)...\n",
- nice(rte->rte_name), points);
+ qPrintable(rte->rte_name), points);
#endif
for (int i = 0; i < points; i++) {
#if GDB_DEBUG
DBG(GDB_DBG_RTE, links)
printf(MYNAME "-rte_pt \"%s\" (%d): %d interlink step(s)\n",
- nice(wpt->shortname), wpt_class, links);
+ qPrintable(wpt->shortname), wpt_class, links);
#endif
for (int j = 0; j < links; j++) {
garmin_ilink_t* il_step = (garmin_ilink_t*) xmalloc(sizeof(*il_step));
#if GDB_DEBUG
DBG(GDB_DBG_RTEe, 1) {
printf(MYNAME "-rte_il \"%s\" (%d of %d): %c%0.6f %c%0.6f\n",
- nice(wpt->shortname), j + 1, links,
+ qPrintable(wpt->shortname), j + 1, links,
il_step->lat < 0 ? 'S' : 'N', il_step->lat,
il_step->lon < 0 ? 'W' : 'E', il_step->lon);
}
#if GDB_DEBUG
DBG(GDB_DBG_RTE, 1)
printf(MYNAME "-rte_pt \"%s\": coordinates = %c%0.6f, %c%0.6f\n",
- nice(wpt->shortname),
+ qPrintable(wpt->shortname),
wpt->latitude < 0 ? 'S' : 'N', wpt->latitude,
wpt->longitude < 0 ? 'W' : 'E', wpt->longitude);
#endif
res->rte_urls.AddUrlLink(UrlLink(FREAD_CSTR_AS_QSTR));
}
#if GDB_DEBUG
- DBG(GDB_DBG_TRK, !res->rte_url.isNull())
+ DBG(GDB_DBG_TRK, res->rte_urls.HasUrlLink())
printf(MYNAME "-trk \"%s\": url = %s\n",
- res->rte_name, qPrintable(res->rte_url));
+ qPrintable(res->rte_name), qPrintable(res->rte_urls.GetUrlLink().url_));
#endif
return res;
}
ivecs->read();
ivecs->rd_deinit();
- cet_convert_strings(global_opts.charset, nullptr, nullptr);
+ cet_convert_strings(global_opts.charset, nullptr);
cet_convert_deinit();
did_something = true;
route_backup(&rte_head_bak);
track_backup(&trk_head_bak);
- cet_convert_strings(nullptr, global_opts.charset, nullptr);
+ cet_convert_strings(nullptr, global_opts.charset);
global_opts.verbose_status = saved_status;
}
ivecs->read();
ivecs->rd_deinit();
- cet_convert_strings(global_opts.charset, nullptr, nullptr);
+ cet_convert_strings(global_opts.charset, nullptr);
cet_convert_deinit();
if (qargs.size() == 2 && ovecs) {
cet_convert_init(ovecs->encode, 1);
- cet_convert_strings(nullptr, global_opts.charset, nullptr);
+ cet_convert_strings(nullptr, global_opts.charset);
if (ovecs->wr_init == nullptr) {
fatal("Format does not support writing.\n");
int saved_status = global_opts.verbose_status;
global_opts.verbose_status = 0;
cet_convert_init(CET_CHARSET_ASCII, 1);
- cet_convert_strings(nullptr, global_opts.charset, nullptr);
+ cet_convert_strings(nullptr, global_opts.charset);
waypt_disp_all(waypt_disp);
global_opts.verbose_status = saved_status;
}